/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package util.ejb;

import entities.tools.FilledForm;
import entities.tools.Form;
import entities.tools.Question;
import entities.users.CompanyOwner;
import entities.users.FormOwner;
import entities.users.FormSigner;
import java.util.List;
import javax.ejb.Local;

/**
 *
 * @author Marek
 */
@Local
public interface FormBeanInterface {

    /**
     * Adds the new question to the existing form
     *
     * @param form
     * @param question
     * @throws java.lang.Exception
     */
    Question createNewQuestion(Form form);

    /**
     * Create the new form entity
     *
     * @return the created before, form instance
     */
    Form createNewForm();

    /**
     * Method Deletes the existing form entity
     *
     * @param form
     * @throws java.lang.Exception
     */
    //TODO: check, if together with the form, are also deleted connected with the form, questions. They should be deleted, when the form is deleted
    void deleteForm(Form form);

    /**
     * Methods return the list of all existing forms TODO: add argument, which
     * will specify sort by argument
     *
     * @return list of all existing in db forms
     */
    List<Form> getAllForms();

    /**
     * Methods return the list of all existing forms, belonging to specified
     * CompanyOwner TODO: add argument, which will specify sort by argument
     *
     * @param companyOwner
     * @return list of all existing in db forms
     * @throws java.lang.Exception
     */
    List<Form> getAllForms(CompanyOwner companyOwner) throws Exception;

    /**
     * Methods return the list of all existing forms, belonging to specified
     * FormOwner TODO: add argument, which will specify sort by argument
     *
     * @param formOwner
     * @return list of all existing in db forms
     * @throws java.lang.Exception
     */
    List<Form> getAllForms(FormOwner formOwner) throws Exception;

    /**
     * Get all questions which belongs to the existing form. Also performs the
     * check if the specified form exist in the database.
     *
     * @param form
     * @return
     * @throws java.lang.Exception
     */
    List<Question> getAllQuestions(Form form);

    /**
     * Get the existing form, assigned to the id number
     *
     * @param id
     * @return form assigned to the id number
     * @throws java.lang.Exception
     */
    Form getExistingForm(Long id);

    /**
     * Method gets the existing FilledForm instance, linked with the existing
     * form Performs the check, if the specified Form exist in database.
     * Performs the check, if the FilledForm with id is in relation with the
     * specified form.
     *
     * @param form
     * @param filledFormId
     * @return the existing FilledForm instance
     * @throws java.lang.Exception
     */
    FilledForm getFilledForm(Form form, Long filledFormId) throws Exception;

    /**
     * Method returns all FilledForm instances connected with the existing Form
     * Also performs the check, if the specified form, exist in the database.
     *
     * @param form
     * @return returns all FilledForm instances connected with the existing F
     * @throws java.lang.Exceptionorm
     */
    List<FilledForm> getFilledForms(Form form) throws Exception;

    /**
     * Searches the database for an entity of the question, containing
     * question_id, and also check if this question is part of specified form
     * Performs the check if the specified form exists in database.
     *
     * @param form
     * @param questionId
     * @return search result
     * @throws java.lang.Exception
     */
    Question getQuestion(Form form, Long questionId);

    /**
     * Method is removing the relation, and also is removing the question
     * entity. TODO: Check: If I removed relation between form and question, the
     * question entity ware be also deleted from database? TODO: Secure the
     * possible scenario of deleting the question which is connected with filled
     * before answers
     *
     * @param form
     * @param question
     * @throws java.lang.Exception
     */
    boolean removeQuestion(Form form, Question question);

    /**
     * Method updates the existing form.
     *
     * @param form
     * @throws java.lang.Exception
     */
    void updateForm(Form form);

    //
    /**
     * Method is performing update of the question connected with the existing
     * form. Question must have not any Answers linked to it.
     *
     * @param form
     * @param question
     * @throws java.lang.Exception
     */
    boolean updateQuestion(Form form, Question question);
    
    

    /**
     * (Dangerous) Method is bypasses security policy. Normally form cannot be deleted, when it had been filled by someone before.
     * Method is performing delete operation on all instances of FilledForm entity, related to the Form, specified by param, and than it deletes also that Form entity, specified by param.
     * @param detachedForm
     * @return true - if operation succeeded false - otherwise
     */
    public boolean forcedDeleteForm(Form detachedForm);
}
